package com.dqyx.test.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Namespace(value="")   
@ParentPackage(value="default")   
@Action(value = "/login", 
	interceptorRefs={@InterceptorRef("baseStack")}   ,
	results = { 
		@Result(name = "success", location = "/welcome.jsp"), 
		@Result(name = "error", location = "/error.jsp")
	}
) 
public class LoginAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2736286904367006112L;
	private String username;
	private String password;
	
	/*
	@Action(value = "/login", 
			interceptorRefs={@InterceptorRef("baseStack")}   ,
			results = { 
				@Result(name = "success", location = "/welcome.jsp"), 
				@Result(name = "error", location = "/error.jsp")
			}) 
			*/
	public String execute() throws Exception
	{
		System.out.println("--123---------------------"+username);
		//当username为crazyit.org，password为leegang时即登录成功
		if (getUsername().equals("1")
			&& getPassword().equals("1") )
		{
			ActionContext.getContext().getSession()
				.put("user" , getUsername());
		return SUCCESS;
		}
		else
		{
			return ERROR;
		}
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	

}
